package com.cy.dda.dao.mapper.cases;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import com.cy.dda.model.domain.cases.Cases;
import com.cy.dda.model.dto.cases.DistributeCasesDTO;
import com.cy.dda.model.dto.message.CasesStatusNotificationMessageDTO;
import com.cy.dda.model.enums.cases.CasesEndStatus;
import com.cy.dda.model.enums.cases.CasesEndType;
import com.cy.dda.model.enums.cases.CasesStatus;
import com.cy.dda.model.query.cases.CasesAdminQuery;
import com.cy.dda.model.query.cases.CasesListQuery;
import com.cy.dda.model.query.statistics.StatisticsCasesCountQuery;
import com.cy.dda.model.vo.cases.CasesAdminVO;
import com.cy.dda.model.vo.cases.CasesDetailInfoAdminVO;
import com.cy.dda.model.vo.cases.CasesDetailInfoVO;
import com.cy.dda.model.vo.cases.CasesListVO;
import com.cy.dda.model.vo.cases.CasesLoanDetailInfoVO;
import com.cy.dda.model.vo.statistics.StatisticsCasesCountVO;
import com.cy.dda.model.vo.user.UserIndexCasesInfoVO;

import tk.mybatis.mapper.common.BaseMapper;

/**
 * Cases
 *
 * @author: tanyilin
 * @create: 2018年10月31日 下午1:59:35
 */
@Mapper
public interface CasesMapper extends BaseMapper<Cases> {

	/**
	 * 查询所有待分配的委案IDs
	 * 
	 * @return
	 */
	List<Long> selectUnDistributeCasesIds();

	/**
	 * 批量分配委案
	 * 
	 * @param list
	 * @param time
	 */
	void distributeCasesBatch(@Param("list") List<DistributeCasesDTO> list, @Param("time") Date time);
	
	/**
	 * 更新委案状态：casesStatus
	 * 
	 * @param casesStatus
	 */
	int updateCasesStatus(@Param("casesId") Long casesId, @Param("casesStatus") CasesStatus casesStatus, @Param("time") Date time);
	
	/**
	 * 更新委案结束状态：casesEndStatus
	 * 
	 * @param casesId
	 * @param casesEndStatus
	 */
	int updateCasesEndStatus(@Param("casesId") Long casesId, @Param("casesEndStatus") CasesEndStatus casesEndStatus, @Param("time") Date time);
	
	/**
	 * 更新委案结束类型：casesEndType
	 * 
	 * @param casesId
	 * @param casesEndType
	 */
	int updateCasesEndType(@Param("casesId") Long casesId, @Param("casesEndType") CasesEndType casesEndType, @Param("time") Date time);
	
	/**
	 * 委案状态：从‘待结束’-->‘处理中’
	 * 
	 * @param casesId
	 * @param time
	 * @return
	 */
	int updateCasesStatusFromEndWaitToProcessing(@Param("casesId") Long casesId, @Param("time") Date time);
	
	/**
	 * 后台查询委案列表总数
	 * 
	 * @param query
	 * @return
	 */
	int selectCasesAdminListCount(CasesAdminQuery query);
	
	/**
	 * 后台查询委案列表数据
	 * 
	 * @param query
	 * @return
	 */
	List<CasesAdminVO> selectCasesAdminList(CasesAdminQuery query);
	
	/**
	 * 查询，后台委案信息详情
	 * 
	 * @param casesId
	 * @return
	 */
	CasesDetailInfoAdminVO selectCasesDetailInfoAdminVO(@Param("casesId") Long casesId);
	
	/**
	 * 查询委案客户所属的委托机构数量
	 * 
	 * @param customerId
	 * @return
	 */
	int selectOrgCountByCustomerId(@Param("customerId") Long customerId);
	
	/**
	 * 查询客户月供委案数量
	 * 
	 * @param customerId
	 * @return
	 */
	int selectMonthlySupplyCasesCountByCustomerId(@Param("customerId") Long customerId);
	
	/**
	 * 委案数据统计数量
	 * 
	 * @return
	 */
	StatisticsCasesCountVO selectStatisticsCasesCountVO(StatisticsCasesCountQuery query);
	
	/**
	 * 查询前台用户首页新派委案信息
	 * 
	 * @param userId
	 * @return
	 */
	List<UserIndexCasesInfoVO> selectUserIndexCasesInfoVO(@Param("userId") Long userId);
	
	/**
	 * 前台-查询委案列表总数
	 * 
	 * @param query
	 * @return
	 */
	int selectCasesListCount(CasesListQuery query);
	
	/**
	 * 前台-查询委案列表
	 * 
	 * @param query
	 * @return
	 */
	List<CasesListVO> selectCasesList(CasesListQuery query);
	
	/**
	 * 前台-委案详情
	 * 
	 * @param casesId
	 * @return
	 */
	CasesDetailInfoVO selectCasesDetailInfoVO(@Param("casesId") Long casesId);
	
	/**
	 * 前台-委案-借款详情
	 * 
	 * @param casesId
	 * @return
	 */
	CasesLoanDetailInfoVO selectCasesLoanDetailInfoVO(@Param("casesId") Long casesId);

	/**
	 * 查询发送委案状态通知消息需要的字段信息
	 * 
	 * @param casesId
	 * @return
	 */
	CasesStatusNotificationMessageDTO selectCasesStatusNotificationMessageDTO(@Param("casesId") Long casesId);
	
	/**
	 * 查询后台-委案编辑，显示的信息
	 * 
	 * @param casesId
	 * @return
	 */
	CasesDetailInfoAdminVO selectCasesEditInfoAdmin(@Param("casesId") Long casesId);
}
